package org.xdq.观察者模式2;

import java.util.Observable;
import java.util.Observer;

public class Thief implements Observer {
    @Override
    public void update(Observable o, Object arg) {

       if(o instanceof Goods){
           if(((Goods)o).isStealed()){
               System.out.println("小偷：得手了！哈哈。");
               new Thread(){
                   @Override
                   public void run() {
                       ((Goods)o).getSecurity().小偷的手();
                   }
               }.start();


           }
       }else{
           int status = (int)arg;
           switch(status){
               case 0:
                   System.out.println("小偷：暗自高兴，没有发现。");
                   //((Security)o).小偷的手();
                   break;
               case 1:
                   System.out.println("小偷：有些担心。");break;
               case 2:
                   System.out.println("小偷：坏了，警察来了。");
                   new Thread(){
                       @Override
                       public void run() {
                           ((Security)o).小偷逃跑();
                       }
                   }.start();


           }

       }
    }
}
